General

fit2 is a non-linear least-squares fitting program. It uses the Levenberg-Marquardt method to attempt to minimize the least-squares error between a data file and a model function. See the books, Data Reduction and Error Analysis in the Physical Sciences by P. R. Bevington and Numerical Recipes in C by W. H. Press et. al. for more information on this method.

Due to the generality of the fitting function allowed, and the possible weirdness of the error function in parameter space, convergance to the true minimum is not guaranteed. Therefore, it is important to have good initial guesses for the parameters. It is a good idea to graph your data and the fitting function with your initial guesses, and tweak the initial guesses until the fitting function is close to the data. Most functions with three or four parameters will converge quickly if the initial guesses are in the right ballpark. If you have more than four parameters, you may have to tell the program to vary only four at a time (the sp command). When the parameters you are varying affect a subset of the data much more than the rest, you should window the data accordingly (the wi command). If these tricks do not work, check and make sure that the function is computing the proper value of the function and derivatives with respect to the parameters. You have to check your source for this. A sign error is disasterous. It will cause the guess for the parameter to be further from the correct value than the current value.

The Levenberg-Marquardt method will work for functions which are linear in the parameters. It is not as fast as linear regression, and it is not guaranteed to converge to an absolute minimum. However, it will do in a pinch and it is actually a little more robust if your basis functions are nearly linearly dependent. Of course, if your basis functions are nearly linearly independent then your parameters will be strongly correlated, and you will have to sort what is meaningful and what is not.

This program was written by Michael Courtney. I consider this a beta version of the program. I retain all rights to the program. You may use the program and alter the source to fit your needs. You may not distribute altered source or executable unless you obtain my permission. You may port this program to other platforms if you wish. It should compile and run almost unaltered on the NeXT platform and most Unix platforms. You may not sell the program or source or receive any money for its distribition. The program is provided as is and is without warranty of guarantee of any kind. The author assumes no responsibility of any kind for anything the program does.

Please report bugs and suggestions to Michael Courtney at michael@amo.mit.edu. I will consider bugs to have a higher priority than suggestions, although suggestions are welcome.

I am considering the following future enhancements to the program:

Please let me know if any of these enhancements are of interest to you.